/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package efe.bean;

import java.io.Serializable;
import java.util.regex.Pattern;

/**
 * Wartość przchowująca adres MAC w formacie XX:XX:XX:XX:XX:XX.
 * @author Paweł
 */
public class EfeMACValue extends EfeByteValue implements Serializable {

    /**
     * Tworzy wartość MAC FF:FF:FF:FF:FF:FF, czyli statndardowo adres
     * rozgłoszeniowy.
     */
    public EfeMACValue() {
        length = 6;
        validate("FF:FF:FF:FF:FF:FF");
    }

    @Override
    public boolean validate(String s) {
        return super.validate(convertToByteFormat(s.trim()));
    }

    private String convertToByteFormat(String s) {
        return "0x" + Pattern.compile(":").matcher(s).replaceAll(" 0x");
    }

    @Override
    public String display() {
        return Pattern.compile(" 0x").matcher(super.display().substring(2))
                .replaceAll(":");
    }

    @Override
    public String getMessage() {
        return "Dane muszą być podane w formacie: XX:XX:XX:XX:XX:XX.";
    }

}
